#include <CascadeFormatter.h>
#include <ExportLengthUnit.h>
#include <LengthUnit.h>
#include <Length.h>
#include <ostream>
#include <sstream>
using namespace std;

void CascadeFormatter::formatUnit(ostringstream& os, const LengthUnit & unit)
{  
  int unitAmount = unit.convertFromBaseUnit(amountOnBaseUnit_m) ;
  if ( 0 != unitAmount  )
  {
    os.str().length() != 0 ? os << " " << Length(unitAmount, unit) : os << Length(unitAmount, unit);
    amountOnBaseUnit_m -= unit.convertToUnit(unitAmount, LengthUnit::baseUnit());
  }
}

void CascadeFormatter::format(ostringstream& os)
{    
    
    const LengthUnit* arrayLenUnit[] = { &MILE, &YARD, &FEET, &INCH };
    for ( int index = 0; index < sizeof (arrayLenUnit)/sizeof(arrayLenUnit[0]); index++ )
    {
       formatUnit( os, *arrayLenUnit[index] );
    }    
}


